package com.test.ml.yqs.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.ml.yqs.entity.TqzTask;
import com.test.ml.yqs.mapper.TqzTaskMapper;
import com.test.ml.yqs.utills.ResultJson;
import com.test.ml.yqs.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 马亮
 * @version V1.0
 * @Description: 定时任务管理
 */
@Service
public class TqzTaskService {

    @Autowired
    private TqzTaskMapper taskMapper;

    /**
     * 分页查询
     *
     * @param taskName
     * @param page
     * @return
     */
    public ResultJson queryList(String taskName, Page page) {

        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<TqzTask> tasks= taskMapper.queryList(taskName);
        PageInfo pageInfo = new PageInfo(tasks);
        return ResultJson.buildSuccess("查询成功",pageInfo);
    }

    /**
     * 新增任务
     * @param task
     * @return
     */
    public ResultJson addTask(TqzTask task) {
        taskMapper.insert(task);
        return ResultJson.buildSuccess("新增成功");
    }

    public ResultJson deleteTask(String[] id) {
        taskMapper.deleteByIds(id);
        return ResultJson.buildSuccess("删除成功");
    }

    public ResultJson updateTask(TqzTask task) {
        taskMapper.update(task);
        return ResultJson.buildSuccess("修改成功");
    }
}